package com.leetcode.algorithm.y22.m09.w4;

/**
 * 1614. 括号的最大嵌套深度
 * 
 * https://leetcode.cn/problems/maximum-nesting-depth-of-the-parentheses/
 * 
 * @author jie.deng
 *
 */
class Question1614Solution01 {
	
	public int maxDepth(String s) {
		int len = s.length();
		int idx = 0;
		int max = 0;
		int depth = 0;
		while (idx < len) {
			if (s.charAt(idx) == '(') {
				depth++;
				if (depth > max) {
					max = depth;
				}
			} else if (s.charAt(idx) == ')') {
				depth--;
			}
			idx++;
		}
		return max;
	}
    
}